import time
from common.functions import open_browser
from common.base import Base,By
from page.frontpage.login_page import LoginPage

class RegisterPag(Base):
    # 注册页面地址
    def get_index(self):
        self.get('http://139.129.26.163/')
        self.click((By.LINK_TEXT, '免费注册'))

    # #定位到用户名输入
    def username_input(self,username):
        self.send_keys((By.NAME,'username'),username)

    # #定位邮箱并输入
    def email_input(self,email):
        self.send_keys((By.NAME, 'email'),email)

    # #定位到密码并输入
    def password1_input(self,password1):
        self.send_keys((By.NAME,'password'),password1)

    #定位到确认密码并输入
    def password2_input(self, password2):
        self.send_keys((By.ID,'conform_password'),password2)

    #定位qq并输入
    def qq_input(self,qq=None):
        self.send_keys((By.NAME,'extend_field2'),qq)

    #定位到手机号并输入
    def phone_tel_input(self,phone_number):
        self.send_keys((By.NAME,"extend_field5"),phone_number)

    #定位到密码下拉框
    def select_password(self, index=2):
        self.select_by_index((By.XPATH, '/html/body/div[6]/div/form/table/tbody/tr[10]/td[2]/select'), index)

    #定位到密码输入问题并输入
    def answer_input(self,answer):
        self.send_keys((By.NAME,'passwd_answer'),answer)

    # #定位注册并点击
    def submit(self,):
        self.click((By.NAME,'Submit'))

    #定位退出
    def logout(self):
        self.click((By.LINK_TEXT,'退出'))

    # 定位登录后页面的用户名
    def get_font_text(self):
        return self.get_element_text((By.CLASS_NAME, 'f4_b'))


if __name__ == '__main__':
    lp =RegisterPag(browser=open_browser())
    lp.get_index()
    lp.username_input('shm12345')
    lp.email_input('221992@163.com')
    lp.password1_input(123456)
    lp.password2_input(123456)
    # lp.answer_input()
    lp.qq_input(123456)
    lp.phone_tel_input(13000000000)
    lp.select_password()
    lp.answer_input('湖北')
    lp.submit()
    # lp.email_input('123456')
    time.sleep(5)
    lp.quit()




